import TimeManage from "../time/TimerManage";

export class TimeUtils {

    private static _temp = new Date();

    //倒计时（最小单位 秒）
    static parseTime(endTime: number, type: FrameType = FrameType.D_H_M_S, unit: TimeUnit = TimeUnit.OBVIOUS) {
        let t = endTime - TimeManage.I.second;
    }

    static format(date: Date, fmt: string) {
        let o: any = {
            "M+": date.getMonth() + 1,                   // 月份 
            "d+": date.getDate(),                        // 日 
            "h+": date.getHours(),                       // 小时 
            "m+": date.getMinutes(),                     // 分 
            "s+": date.getSeconds(),                     // 秒 
            "q+": Math.floor((date.getMonth() + 3) / 3), // 季度 
            "S": date.getMilliseconds()                  // 毫秒 
        };
        let re = /(y+)/;
        if (re.test(fmt)) {
            let t = re.exec(fmt)[1]
            fmt = fmt.replace(t, (date.getFullYear() + "").substring(4 - t.length));
        }
        for (let k in o) {
            let reg = new RegExp("(" + k + ")")
            if (reg.test(fmt)) {
                let t = reg.exec(fmt)[1];
                fmt = fmt.replace(t, (t.length == 1) ? (o[k]) : (("00" + o[k]).substring(("" + o[k]).length)));
            }
        }
        return fmt;
    }

}

export enum FrameType {
    DD_HH_MM_SS,
    D_H_M_S,
    HH_MM_SS,
    H_M_S,
}

export enum TimeUnit {
    OBVIOUS,    //1天2时3秒
    SPARE,      //1d2h2s
    VACANCY,    //1:2:3

}